package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.NewsDetail;
import com.qf.entity.NewsDetailExample;
import com.qf.mapper.NewsDetailMapper;
import com.qf.service.NewsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 10537
 * @version V1.0
 * @Date 2021/10/6 11:34
 */
@Service
public class NewsDetailServiceImpl implements NewsDetailService {
    @Autowired
    private NewsDetailMapper newsDetailMapper;
    @Override
    public PageInfo<NewsDetail> findByTitleAndPage(Integer paage, Integer rows, String title) {
        NewsDetailExample example=new NewsDetailExample();
        NewsDetailExample.Criteria criteria = example.createCriteria();
        criteria.andTitleLike(title);
        PageHelper.startPage(paage,rows);
        List<NewsDetail> list = newsDetailMapper.selectByExample(example);
        PageInfo<NewsDetail> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void removeById(Integer id) {
        int i = newsDetailMapper.deleteByPrimaryKey(id);
        if (i!=1){
            System.out.println("删除新闻信息失败");
            throw new RuntimeException("删除新闻信息失败");
        }
    }
}
